{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## t-SNE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.manifold import TSNE\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ts = TSNE(n_components=2)\n",
    "ts.fit_transform(out.to('cpu').detach().numpy())\n",
    "\n",
    "x = ts.embedding_\n",
    "y = cora.y.to('cpu').detach().numpy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xi = []\n",
    "for i in range(7):\n",
    "    xi.append(x[np.where(y==i)])\n",
    "\n",
    "colors = ['mediumblue','green','red','yellow','cyan','mediumvioletred','mediumspringgreen']\n",
    "plt.figure(figsize=(16, 12))\n",
    "\n",
    "for i in range(7):\n",
    "    plt.scatter(xi[i][:,0],xi[i][:,1],s=30,color=colors[i],marker='o',alpha=1, zorder=2)\n",
    "\n",
    "for edge in draw_edge_index:\n",
    "    start, end = edge\n",
    "    plt.plot([x[start][0],x[end][0]],[x[start][1],x[end][1]],color='gray', alpha = 0.2, zorder=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pycharts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts.options as opts\n",
    "from pyecharts.charts import Graph\n",
    "\n",
    "from pyecharts.globals import CurrentConfig, NotebookType\n",
    "CurrentConfig.NOTEBOOK_TYPE = NotebookType.NTERACT\n",
    "\n",
    "colors = ['#191970','#008000','#FF0000','#FFFF00', '#00FFFF', '#C71585', '#00FA9A']\n",
    "\n",
    "nodes = []\n",
    "\n",
    "for i in range(cora.x.shape[0]):\n",
    "    nodes.append(\n",
    "                {\"x\": int(x[i][0]),\n",
    "                 \"y\": int(x[i][1]),\n",
    "                 \"id\": str(i),\n",
    "                 \"name\": str(i),\n",
    "                 \"symbolSize\": 3,\n",
    "                 \"itemStyle\": {\"normal\": {\"color\": colors[y[i]]}}}\n",
    "                )\n",
    "    \n",
    "edges = [\n",
    "    {\"source\": str(edge[0]), \"target\": str(edge[1])} for edge in draw_edge_index\n",
    "]\n",
    "\n",
    "(\n",
    "    Graph(init_opts=opts.InitOpts(width=\"1600px\", height=\"800px\"))\n",
    "    .add(\n",
    "        series_name=\"\",\n",
    "        nodes=nodes,\n",
    "        links=edges,\n",
    "        layout=\"none\",\n",
    "        is_roam=True,\n",
    "        is_focusnode=True,\n",
    "        label_opts=opts.LabelOpts(is_show=False),\n",
    "        linestyle_opts=opts.LineStyleOpts(width=0.5, curve=0, opacity=0.7),\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"NPM Dependencies\"))\n",
    "#     .render_notebook()\n",
    "    .render(\"npm_dependencies.html\")\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "song",
   "language": "python",
   "name": "song"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
